package com.example.barry.pdf.Net;

import android.os.AsyncTask;
import android.os.Handler;
import android.os.Message;
import android.util.Log;


import com.example.barry.pdf.PgSQL.SFDCConf;
import com.example.barry.pdf.PgSQL.ServerInfo;
import com.example.barry.pdf.PgSQL.postgresSQL;
import com.example.barry.pdf.PgSQL.postgresSQLimpl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by barry on 17-1-11.
 */

public class GetUnitIdAsynTask extends AsyncTask<String,Void,List<Map<String,Object>>>{
    private postgresSQL pSQL = new postgresSQLimpl();
    private List<Map<String,Object>> unitIdmap = new ArrayList<Map<String, Object>>();
    Handler handler;



    public GetUnitIdAsynTask(Handler handler){this.handler = handler;}
    protected List<Map<String,Object>> doInBackground(String...params){

        int sfdcSerId = Integer.parseInt(params[1]);
        ServerInfo sInfo = pSQL.getServerInfo(params[0], sfdcSerId);
        List<SFDCConf> stationList = pSQL.getStationId(params[0], sfdcSerId);
        for (int j = 0; j < stationList.size(); j++) {

                SFDCConf sConf = stationList.get(j);
                Map<String, Object> m = new HashMap<String, Object>();
                //m.put("sfdcser_Id", sInfo.getServerId());
                m.put("sfdcser_name", sInfo.getName());
                m.put("deviceid", sConf.getDeviceid());
                //	m.put("clientname", sConf.getClientname());
                m.put("description", sConf.getDescription());
                //	m.put("active", sConf.getActive());
                m.put("devicetype", sConf.getDevicetype());
                //m.put("id", sConf.getId());
                m.put("devicecode", sConf.getDevicecode());
                unitIdmap.add(m);

        }
      //  Log.i("UnitId",""+unitIdmap);
        return unitIdmap;
    }

    protected void onPostExecute(List<Map<String, Object>> result) {
       // Log.i("result", "" + result);
        Message msg = new Message();
        msg.what = 0x123;
        msg.obj  = result;
        handler.sendMessage(msg);
    }
}
